
cc.Class({
    extends: cc.Component,

    properties: {
        className:"timerlayer",
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad: function () {
        this.node.thisJS = this;
        this.timer =  cc.find("timer",this.node);
        this.timer_label =  cc.find("timer_label",this.timer);
        this.initUI();
    },
    start: function () {
       
    },
    initUI: function(){
        EventManager.addEventObeserveF(EventConfig.startTimer, handler(this,
            this.startTimer),"timerlayer");
        EventManager.addEventObeserveF(EventConfig.stopTimer, handler(this,
            this.stopTimer),"timerlayer");
        
    },
    
    //玩家进入桌子,更新个人信息  
    startTimer:function(time){
        Log.logd("收到消息"); 
        this.timer_label.getComponent(cc.Label).string  = time + "";
        this.timer.active = true ;
        if(this._timecount_id){
            this.unschedule(this._timecount_id);
            this._timecount_id = null;
        }
        this._timecount_id = function (){     
            time =time -1;    
            if(time<0){
                this.unschedule(this._timecount_id);
                this._timecount_id = null;
                this.timer.active = false;
            }
            else{
                this.timer_label.getComponent(cc.Label).string  = time + "";
            }  
        }
        this.schedule(this._timecount_id,1);
    },

    stopTimer:function(time){
        if (this._timecount_id ){
           this.unschedule(this._timecount_id);
           this._timecount_id = null;
        }
        this.timer.active = false ;
    }
});